package com.woniu.apartment.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.woniu.apartment.mapper.WishMapper;
import com.woniu.apartment.domain.Wish;
import com.woniu.apartment.service.IWishService;

/**
 * 用户收藏房型和公寓列Service业务层处理
 *
 * @author yy
 * @date 2023-04-03
 */
@Service
public class WishServiceImpl implements IWishService
{
    @Autowired
    private WishMapper wishMapper;

    /**
     * 查询用户收藏房型和公寓列
     *
     * @param id 用户收藏房型和公寓列主键
     * @return 用户收藏房型和公寓列
     */
    @Override
    public Wish selectWishById(Long id)
    {
        return wishMapper.selectWishById(id);
    }

    /**
     * 查询用户收藏房型和公寓列列表
     *
     * @param wish 用户收藏房型和公寓列
     * @return 用户收藏房型和公寓列
     */
    @Override
    public List<Wish> selectWishList(Wish wish)
    {
        return wishMapper.selectWishList(wish);
    }

    /**
     * 新增用户收藏房型和公寓列
     *
     * @param wish 用户收藏房型和公寓列
     * @return 结果
     */
    @Override
    public int insertWish(Wish wish)
    {
        return wishMapper.insertWish(wish);
    }

    /**
     * 修改用户收藏房型和公寓列
     *
     * @param wish 用户收藏房型和公寓列
     * @return 结果
     */
    @Override
    public int updateWish(Wish wish)
    {
        return wishMapper.updateWish(wish);
    }

    /**
     * 批量删除用户收藏房型和公寓列
     *
     * @param ids 需要删除的用户收藏房型和公寓列主键
     * @return 结果
     */
    @Override
    public int deleteWishByIds(Long[] ids)
    {
        return wishMapper.deleteWishByIds(ids);
    }

    /**
     * 删除用户收藏房型和公寓列信息
     *
     * @param id 用户收藏房型和公寓列主键
     * @return 结果
     */
    @Override
    public int deleteWishById(Long id)
    {
        return wishMapper.deleteWishById(id);
    }

    @Override
    public Wish likeById(Long apartmentId, Long userId) {
        return wishMapper.likeById(apartmentId,userId);
    }

    @Override
    public int changeWish(Long apartmentId, Long userId) {
        Wish wish = wishMapper.likeById(apartmentId, userId);
        if (wish != null) {
            wishMapper.deleteWishById(wish.getId());
            return 0;
        }else {
        Wish wish1 = new Wish();
        wish1.setApartmentId(apartmentId);
        wish1.setCustomerId(userId);
        wishMapper.insertWish(wish1);
            return 1;
        }
    }


}
